﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Convertor.Interface;
using Wpf.CommonTools;

namespace Convertor
{
    /// <summary>
    /// LoadPluginWindow.xaml 的交互逻辑
    /// </summary>
    public partial class LoadPluginWindow : Window, IManagePluginControl, IMyWindows
    {
        private ManagePluginControl pluginControl;

        public LoadPluginWindow()
        {
            pluginControl = new ManagePluginControl();
            InitializeComponent();
        }

        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            PluginLoader.Children.Add(pluginControl);
            ((IMyWindows)pluginControl).MyWindows = MyWindows;
        }

        private bool close;
        private void Window_KeyDown(object sender, KeyEventArgs e)
        {
            if (Config.GlobalConfig.EnableEscToCloseChildWindows && this.IsActive && e.Key == Key.Escape)
            {
                close = true;
            }
        }

        private void Window_KeyUp(object sender, KeyEventArgs e)
        {
            if (close && Config.GlobalConfig.EnableEscToCloseChildWindows && this.IsActive && e.Key == Key.Escape)
            {
                this.Close();
            }
        }

        private void Button_OK_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
            this.Close();
        }

        private void Button_Cancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        #region IManagePluginControl 成员

        public ObservableDictionary<string, object> AllPlugins
        {
            get
            {
                return ((IManagePluginControl)pluginControl).AllPlugins;
            }
            set
            {
                ((IManagePluginControl)pluginControl).AllPlugins = value;
            }
        }


        public string TempPluginsPath
        {
            get
            {
                return ((IManagePluginControl)pluginControl).TempPluginsPath;
            }
            set
            {
                ((IManagePluginControl)pluginControl).TempPluginsPath = value;
            }
        }

        public IPluginsItemCollection SelectedPlugins
        {
            get
            {
                return ((IManagePluginControl)pluginControl).SelectedPlugins;
            }
            set
            {
                ((IManagePluginControl)pluginControl).SelectedPlugins = value;
            }
        }

        //public ISelectedPluginsContainer SelectedPlugins
        //{
        //    get
        //    {
        //        return ((IManagePluginControl)pluginControl).SelectedPlugins;
        //    }
        //    set
        //    {
        //        ((IManagePluginControl)pluginControl).SelectedPlugins = value;
        //    }
        //}

        public IPluginItem CurrentPlugin
        {
            get
            {
                return ((IManagePluginControl)pluginControl).CurrentPlugin;
            }
            set
            {
                ((IManagePluginControl)pluginControl).CurrentPlugin = value;
            }
        }
   
        #endregion

        #region IMyWindows 成员

        public Window MyWindows { get; set; }

        #endregion

    }
}
